﻿using SqlSugar;
using System.ComponentModel.DataAnnotations;
using System.Text.Json;
using Vampirewal.BlogCore.DataAccess;
using static System.Formats.Asn1.AsnWriter;

namespace Vampirewal.BlogCore.TestWebApi;

public class TestMessage : IVampirewalMessageManager
{
    private readonly IServiceScope Scope;

    public TestMessage(IServiceScopeFactory Factory)
    {
        Scope= Factory.CreateScope();
    }


    [RegistMethod]
    public string TestClick(testClass tt)
    {
        return tt.Field1;
    }

    [RegistMethod]
    public TestFormModel TestFormClick(TestFormModel input)
    {
        //return JsonSerializer.Serialize(input);
        return input;
    }

    [RegistMethod]
    public async void SubmitMessageBoard(MessageBoardForm input)
    {
        var rep= Scope.ServiceProvider.GetRequiredService<SimpleClient<MessageBoardForm>>();

        await rep.InsertAsync(input);
    }
}

public class testClass
{
    [Required(ErrorMessage = "字段不能为空")]
    public string Field1 { get; set; }

    public int Field2 { get; set; }
}